package vip.specimen.system.datasource.validation.question;


import vip.specimen.system.datasource.entity.question.QuestionColumnEntity;
import vip.specimen.system.service.question.ColumnService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * *@Author: 余浪人
 * *@Date：2021/4/26 15:11
 * *@Email:yulangren520@Gmail.com
 * *@QQ:1368419640
 **/
public class ColumnUniqueImp implements ConstraintValidator<ColumnUnique, String> {
    @Resource
    private ColumnService columnService;
    @Resource
    private HttpServletRequest request;

    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        QuestionColumnEntity columnEntity = this.columnService.findByColumnName(s);
        return null == columnEntity || columnEntity.getUuid().toString().equals(request.getParameter("uuid"));
    }
}
